import { CircleNode, CircleNodeModel, h } from "@logicflow/core";

class RoundTaskNode extends CircleNode {
	getShape() {
		const { model } = this.props;
		const { x, y, width, height, radius } = model;
		const style = model.getNodeStyle();
		return h("g", {}, [
			h("rect", {
				...style,
				x: x - width / 2,
				y: y - height / 2,
				rx: radius,
				ry: radius,
				width,
				height,
			}),
		]);
	}
}

class RoundTaskModel extends CircleNodeModel {
	initNodeData(data: any) {
		super.initNodeData(data);
		this.r = 40;
		this.radius = 50;
	}

	getNodeStyle() {
		const style = super.getNodeStyle();
		return style;
	}

	getTextStyle() {
		const style = super.getTextStyle();
		style.fill = "blank";
		return style;
	}

	// 整体结构样式
	getAnchorStyle(anchorInfo: any) {
		const style = super.getAnchorStyle(anchorInfo);
		style.stroke = "aqua"; // 默认边框色
		style.r = 6;
		style.hover.r = 8;
		style.hover.fill = "aqua"; // hover 时背景填充色
		style.hover.stroke = "aqua"; // hover 时边框色
		return style;
	}
}

export const roundTask = {
	type: "RoundTask",
	view: RoundTaskNode,
	model: RoundTaskModel,
};
